#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from mysql.src.common.constant import MysqlBackupToolName


def is_use_xtrabackup(tool_name):
    if not tool_name:
        return False
    return tool_name in [MysqlBackupToolName.XTRBACKUP2, MysqlBackupToolName.XTRBACKUP8] or is_custom_xtrabackup_tool(
        tool_name)


def is_use_password_tool(tool_name):
    if not tool_name:
        return False
    return tool_name in [MysqlBackupToolName.MYSQLDUMP,
                         MysqlBackupToolName.MYSQL, MysqlBackupToolName.XTRBACKUP8] or is_custom_xtrabackup_tool(
        tool_name)


def is_custom_xtrabackup_tool(tool_name):
    if not tool_name:
        return False
    return tool_name.endswith(
        "xtrabackup") or tool_name.endswith("xtrabackup2") or tool_name.endswith("xtrabackup8")


def is_use_xtrabackup2(tool_name: str):
    if not tool_name:
        return False
    return tool_name == MysqlBackupToolName.XTRBACKUP2 or tool_name.endswith("xtrabackup2") or (
            tool_name.endswith("xtrabackup") and "xtrabackup-2" in tool_name)


def is_use_xtrabackup8(tool_name: str):
    if not tool_name:
        return False
    return tool_name == MysqlBackupToolName.XTRBACKUP8 or tool_name.endswith("xtrabackup8") or (
            tool_name.endswith("xtrabackup") and "xtrabackup-8" in tool_name)
